import {useState,useEffect} from 'react'
export function useWindowSize(){
    // 获取窗口
    const [size,setSize] = useState({
      width: document.documentElement.clientWidth,
      height:document.documentElement.clientHeight
    })

    const handleResize = () =>{
      setSize({
        width: document.documentElement.clientWidth,
        height:document.documentElement.clientHeight
      })
    }
    useEffect(()=>{
      window.addEventListener('resize',handleResize)
      // return是回调函数
      return()=>{
        window.removeEventListener('resize',handleResize)
      }
      // []
    },[])
    // 函数返回
    // return[size]
    return size
}
